import Book.*;
import User.*;

import java.sql.SQLException;
import java.util.Scanner;
public class Main {
    public static User Login() {
        Scanner scanner = new Scanner(System.in);
        System.out.println("--------------------------");
        System.out.println("***  欢迎来到图书管理系统  ***");
        System.out.println("--------------------------");
        System.out.println("        1.管理员           ");
        System.out.println("        2.普通用户          ");
        System.out.println("--------------------------");
        System.out.print("请输入你的身份#: ");
        int choice = scanner.nextInt();
        scanner.nextLine();
        String userName;
        String userPasswd;
        if (choice == 1) {
            System.out.print("请输入管理员用户名: ");
            userName = scanner.nextLine();
            System.out.print("请输入管理员密码: ");
            userPasswd = scanner.nextLine();
            new Login().LoginInfo(userName, userPasswd);
            return new AdminUser(userName);//向上转型
        } else {
            System.out.print("请输入普通用户名: ");
            userName = scanner.nextLine();
            System.out.print("请输入用户名密码: ");
            userPasswd = scanner.nextLine();
            System.out.println("成功登录图书管理系统!");
            return new DomeUser(userName);
        }
    }

    public static void main(String[] args) throws SQLException {
        //1.准备数据
        Bookshelf bookshelf = new Bookshelf();
        //2.登录
        User user = Login();
        while (true) {
            int choice = user.menu();
            user.doIOperator(choice, bookshelf);
        }
    }
}
